package com.yc.example.main;

import android.os.Bundle;
import android.support.v4.view.ViewPager;

import com.yc.example.R;
import com.yc.example.main.mepage.MeFragment;
import com.yc.example.main.messagpage.MessagePageFragment;
import com.yc.example.main.redpackagepage.RedPkgFragment;
import com.yc.mvplib.Basis.BasisActivity;
import com.yc.mvplib.Basis.BasisFragment;
import com.yc.mvplib.widget.TabLayoutView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MainActivity extends BasisActivity<MainPresenter, MainModel> {
    @BindView(R.id.viewpager)
    ViewPager viewPager;
    @BindView(R.id.tabview)
    TabLayoutView tabLayoutView;
    private String[] titles = {"消息", "红包", "我的"};
    private int[] imgs = {R.drawable.nav_nearby_selector, R.drawable.nav_circle_selector, R.drawable.nav_message_selector, R.drawable.nav_find_selector, R.drawable.nav_me_selector};
    private List<BasisFragment> fragmentPages;
    @Override
    public int getContentLayout() {
        return R.layout.activity_main;
    }

    @Override
    public void loadData() {
        if (mModel != null) {
            mModel.loadData();
        }
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        initFragments();
        tabLayoutView.setDataSource(titles, imgs, 0);
        tabLayoutView.setImageStyle(25, 25);
        tabLayoutView.setTextStyle(12, R.color.color_999999,R.color.color_ff78a3);
        tabLayoutView.initDatas();
        setDots();
        tabLayoutView.setOnItemOnclickListener(new TabLayoutView.OnItemOnclickListener() {
            @Override
            public void onItemClick(int index) {
                viewPager.setCurrentItem(index, true);
            }
        });

        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                viewPager.setCurrentItem(position, false);
                tabLayoutView.setSelectStyle(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private void setDots() {

    }

    private void initFragments() {
        fragmentPages=new ArrayList<>();
        fragmentPages.add(new MessagePageFragment());
        fragmentPages.add(new RedPkgFragment());
        fragmentPages.add(new MeFragment());
    }



    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


}
